import com.troyworks.framework.BaseStatefulObject;
import com.troyworks.hsmf.AEvent;
import com.troyworks.hsmf.Hsmf;
/**
 * @author Troy Gardner
 */
class com.troyworks.tester.BaseTester extends Hsmf {
   //////////////////////////////// ATTRIBUTES //////////////////////////////
	public var myTests:Array = new Array();
	//public var tracesOn:Boolean = false;
	/************************************************
	 *  Constructor 
	 */
	public function BaseTester(initState : Function, name:String) {
		super((initState == null)?s_initial:initState, (name== null)?"BaseTester": name);
	}
	//////////////////////////////// METHODS //////////////////////////////////
	public function loadSubTasks():Void{
		trace("LLLLLLLLLLLL loading Subtasks LLLLLLLLLLLL");
	}
	//////////////////////////////// EVENTS (Generators)  /////////////////////////////////////
	
	////////////////////////////////  STATES ////////////////////////////////////
	/*..PSEUDOSTATE...............................................................*/
	function s_initial(e : AEvent) : Function
	{
	//	trace("s_initial-----------" + e.sig.name);
		onFunctionEnter ("s_initial-", e, []);
		if(e.sig == Q_INIT_SIG){
			trace("s_initial.ENTER-----------------------" + Q_INIT);			
			Q_INIT(s_ready);
		}
		return null;
	}
	/*.................................................................*/
	function s_ready(e : AEvent) : Function
	{
	//	trace("s_ready-----------"  + e.sig.name);
		onFunctionEnter ("s_ready-", e, []);
		switch (e.sig)
		{
			case Q_ENTRY_SIG :
			{
				trace("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
				trace("TTTTTTTTTTTTTTTTTTTTTT TEST RUNNER BEGIN TTTTTTTTTTTTTTTTTTTTTT");
				trace("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
				
				loadSubTasks();
				return null;
			}
			case Q_INIT_SIG :
			{
				trace("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
				trace("TTTTTTTTTTTTTTTTTTTTTT TEST RUNNER myTests.length: " + myTests.length+ " TTTTTTTTTTTTTTTTTTTTTT");
				trace("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
			
				if(myTests.length >0){
					Q_INIT(s__runningTest);
				}else{
					callbackIn();
				}
				return null;
			}
			case Q_CALLBACK_SIG:
			{
				Q_dispatch(TERMINATE_EVT);
				return null;
			}
			case Q_TERMINATE_SIG:
			{
				trace("ZZZZZZZZZZZZZZZZZZZZZZZ TERMINATE SIG ATTEMPTING TO END ZZZZZZZZZZZZZZZZZZ");
				Q_TRAN(s_final);
				return null;
			}
		}
		return s_top;
	}
	/*.................................................................*/
	function s__runningTest(e : AEvent) : Function
	{
		onFunctionEnter ("s_runningTest-", e, []);
		switch (e.sig)
		{
			case Q_ENTRY_SIG :
			{
				trace("Beginning Test--------------------");
			//	dispState("calc");
				return null;
			}
			case Q_INIT_SIG :
			{
				clear();
			//	Q_INIT(s__ready);
				return null;
			}
			case Q_TERMINATE_SIG:
			{
				Q_TRAN(s_final);
				return null;
			}
		}
		return s_ready;
	}
	/*..PSEUDOSTATE...............................................................*/
	function s_final(e : AEvent) : Void
	{
		this.onFunctionEnter ("s_final-", e, []);
		switch (e.sig)
		{
			case Q_ENTRY_SIG :
			{ 
				trace("ZZZZZZZZZZZZZZZ FINISHED ALL TESTS ZZZZZZZZZZZZZZZZZZZZ");
				return;
			}
		}
	}
	
}